/*
Copyright (c) 2006, Bruce Weirdan
All rights reserved.

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the following conditions are met:

    * Redistributions of source code must retain the
above copyright notice, this list of conditions and
the following disclaimer.
    * Redistributions in binary form must reproduce
the above copyright notice, this list of conditions
and the following disclaimer in the documentation
and/or other materials provided with the distribution.
    * The name of the copyright holder may NOT be used
to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

// @include   http://www.livejournal.com/update.bml

Sites.LiveJournal_newPost = {
    initUI : function(store) {/*{{{*/
        var insertObjSpan = document.evaluate(
           '//span[@id="insobj"]',
           document,
           null,
           XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
           null
        ).snapshotItem(0);

        var dropDownButton = document.createElement('input');
        dropDownButton.type = 'button';
        dropDownButton.value = 'Smilies!';
        dropDownButton.className = 'button';
        dropDownButton.style.marginLeft = '4px';

        var smiliesContainer = document.createElement('div');
        smiliesContainer.style.border = 'silver solid 2px';
        smiliesContainer.style.display = 'none';
        smiliesContainer.style.position = 'absolute';
        smiliesContainer.style.background = 'white';

        dropDownButton.addEventListener('click', function(e) {
            if(smiliesContainer.style.display == 'block')   
                smiliesContainer.style.display = 'none';
            else
                smiliesContainer.style.display = 'block';
            e.preventDefault();
        }, false);

        insertObjSpan.appendChild(dropDownButton);
        insertObjSpan.appendChild(smiliesContainer);
        store.getEnabled().forEach(function(href) {
            var img = document.createElement('img');
            img.src = href;
            img.style.border = 'white 1px solid';
            img.addEventListener('mouseover', function(e) {
                img.style.borderColor = 'silver silver silver silver';
            }, false);
            img.addEventListener('mouseout', function(e) {
                img.style.borderColor = 'white white white white';
            }, false);
            img.addEventListener('click', function(e) {
                var message = document.getElementsByName('event').item(0);
                message.value += '<img src="' + href + '" />';
                smiliesContainer.style.display = 'none';
            }, false);
            smiliesContainer.appendChild(img);
        });
    },/*}}}*/

    isThisSite : function() {/*{{{*/
        var hostLJ = (window.location.hostname == 'www.livejournal.com');
        var pageLJ = (window.location.pathname == '/update.bml');
        return hostLJ && pageLJ;
    }/*}}}*/
};
